package com.kly.test.function
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import com.kly.test.base.BaseVMActivity
import com.kly.test.databinding.ActivityMainBinding
import com.kly.test.function.home.HomeFragment
import com.kly.test.function.me.MeFragment
import com.kly.test.function.like.LikeListFragment

class MainActivity : BaseVMActivity<ActivityMainBinding, MainViewModel>(
    ActivityMainBinding::inflate,
    MainViewModel::class.java
) {
    override fun initData() {
        initialViews()
    }

    private fun initialViews() {
        binding.viewPager.offscreenPageLimit = 3
        binding.viewPager.isScrollable = false
        binding.viewPager.adapter = object :
            FragmentPagerAdapter(supportFragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
            override fun getCount(): Int = 3
            override fun getItem(position: Int): Fragment {
                return when (position) {
                    0 -> HomeFragment()
                    1 -> LikeListFragment()
                    else -> MeFragment()
                }
            }
        }

        binding.navigation.attach(binding.viewPager)
        binding.navigation.setListener(object : NavigationLayout.Callback {
            override fun onItemClick(position: Int): Boolean {
                binding.viewPager.setCurrentItem(position, false)
                return false
            }

            override fun onItemClickAgain(position: Int) {
            }
        })

    }
}